//Developed by Mudassar Raza
#include <stdio.h>
#include<conio.h>
#include<dos.h>
int ya=20,yb=20,yc=20;
int xa=10,xb=25,xc=40;
void towers(int height, char from, char to, char temp);
void clear_from(char from);
void add_to(char to);
void main()
{
int n,i; char a='A',b='B',c='C';
clrscr();
printf("\nEnter the number of discs to start with:: ");
scanf("%d",&n);
gotoxy(xa,yb+5);
printf("A");
gotoxy(xb,yb+5);
printf("B");
gotoxy(xc,yb+5);
printf("C");
for(i=n;i>=1;i--)
  {
  add_to('A');
  cprintf("%d",i);
  }
printf("\n\n");
towers(n,a,c,b);
printf("\n\n");
getch();
}
void towers(int height, char from, char to, char temp)
{
if(height==1)
      { delay(500);
       clear_from(from);
       add_to(to);
       cprintf("1");
       return;
      }
      delay(500);
      towers(height-1,from,temp,to);
      delay(500);
       clear_from(from);
       add_to(to);
       cprintf("%d",height);
      towers(height-1,temp,to,from);
}
void clear_from(char from)
{
      if(from=='A')
	{
	 gotoxy(xa,ya++);
	 cprintf(" ");
	}
      if(from=='B')
	{
	 gotoxy(xb,yb++);
	 cprintf(" ");
	}
      if(from=='C')
	{
	 gotoxy(xc,yc++);
	 cprintf(" ");
	}
}
void add_to(char to)
{
   if(to=='A')
     gotoxy(xa,--ya);
   if(to=='B')
     gotoxy(xb,--yb);
   if(to=='C')
      gotoxy(xc,--yc);
}
